package com.eflow.model.flowable.converter;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.eflow.model.domain.EflowUser;
import com.eflow.model.flowable.model.UserElement;
import com.eflow.model.flowable.model.e.UserTypeEnum;
import com.eflow.model.service.IEflowUserService;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author hui se
 * @description
 * @create 2021-03-05 18:21
 **/
@Component
public class UserListConverter extends BaseUserListConverter  {
    @Autowired
    private IEflowUserService eflowUserService;

    @Override
    List<EflowUser> list(UserElement userElement, String loginUser, ProcessDefinition processDefinition, String processInstanceId, String activityId, Map<String,Object> var) {
        List<Map> userList = (List) userElement.getData();
        List<String> userIds = userList.stream().map(x -> StrUtil.toString(x.get("userId"))).collect(Collectors.toList());
       if(!userIds.isEmpty()){
           return  eflowUserService.selectUserByUserIds(userIds);
       }else {
           return new ArrayList<>();
       }
    }

    @Override
    UserTypeEnum getUserType() {
        return UserTypeEnum.LIST;
    }
}
